<?php
class Biaya_lain extends Authenticated_Controller{
	function __construct() {
		parent::__construct();
		$this->load->model('biaya_model','biaya');
		$this->load->model('user_model','user');
		$this->load->model('coa_model','coa');
		$this->load->model('reservasi_model','reser');
	}
	function index(){
		$this->list_biaya_lain();
	}
	function list_biaya_lain($tgl=''){
		$qry_coa = $this->coa->get_all();
		for($i=0;$i<count($qry_coa);$i++){
			$list_coa[$qry_coa[$i]['id'].'-'.$qry_coa[$i]['kode_coa'].'-'.$qry_coa[$i]['nama_coa']]=$qry_coa[$i]['nama_coa'];
		}
		$data['list_coa']=$list_coa;
		if($this->session->userdata('level')==0)
                    $data['list_biaya'] = $this->biaya->get_biaya_lain($tgl);
                else
                    $data['list_biaya'] = $this->biaya->get_biaya_lain_for_kasir($this->session->userdata('kota'),$tgl);
		if($tgl==''){
			$data['date']=date('m/d/Y');
		}else{
			$data['date']=$this->date_func->change_format_date($tgl,'d-m-Y','m/d/Y');
		}
                if($this->session->userdata('level')!=4)
                    $data['list_opt_spj']= $this->biaya->get_no_spj_per_day($tgl);
                else
                    $data['list_opt_spj']= $this->biaya->get_no_spj_per_day_for_kasir($this->session->userdata('kota'),$tgl);
		$this->load->view('template/header_view');
		$this->load->view('biaya_lain/list_biaya', $data);
		$this->load->view('template/footer_view');
	}
	
	function biaya_lain_process(){
		$data['NoSPJ'] = $_POST['no_spj'];
		$data['tgl_pembayaran'] = $this->date_func->change_format_date($_POST['tgl_bayar'],'d-m-Y','Ymd');
		$data['idkasir']=$this->session->userdata('id');
		$data['cabang']=$_POST['asal'];
		
		$jenis_biaya = $_POST['jenis_biaya'];
		$jumlah = $_POST['jumlah'];
		$jenis = $_POST['jenis'];
		
		for($i=0;$i<count($jenis_biaya);$i++){
			$data_biaya = explode('-', $jenis_biaya[$i]);
			$data['idbiaya'] = $data_biaya[0];
			$data['kode_coa_biaya'] = $data_biaya[1];
			$data['nama_coa'] = $data_biaya[2];
			$data['is_tujuan']=$jenis[$i];
			$data['jumlah']=$jumlah[$i];
			$this->biaya->insert_data($data);
		}
		redirect(BIAYA.'list_biaya_lain/'.$_POST['tgl_bayar']);
	}
	
	function data_reservasi($no_spj){
		
		$reservasi = $this->reser->get_one($no_spj);
		$data['no_spj']=$no_spj;
		$data['no_pol']=$reservasi['NoPol'];
		$data['driver']=$reservasi['Driver'];
		$data['asal']=$reservasi['Asal'];
		$data['tujuan']=$reservasi['Tujuan'];
		$data['tgl_pembayaran']=date('m/d/Y');
		$jumlah_seat=$this->reser->get_jumlah_seat($no_spj);
		$data['kapasitas']=$jumlah_seat['JumlahKursi'];
		$jum_penumpang=$this->reser->get_jumlah_penumpang($no_spj);
		$data['jumlah_penumpang']=$jum_penumpang['PesanKursi'];
		$subtotal=$this->reser->get_subtotal($no_spj);
		$data['penjualan_kotor']=$subtotal['SubTotal'];
		echo json_encode($data);
	}
	
	function cetak($id){
		$data=$this->biaya->get_data_cetak($id);
		$this->load->view('biaya_lain/html_cetak',$data);
	}
}
